package com.chen.admin.service;


import com.chen.admin.common.Result;
import com.chen.admin.entity.AdminLogin;
import com.chen.admin.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminService {



    @Autowired
    private AdminMapper adminMapper;

    public Result login(AdminLogin adminLogin) {

       AdminLogin admin= adminMapper.login(adminLogin);
       if(admin==null){
           return Result.error("400","没有此用户");
       }
       return Result.success("登录成功");
    }

    public Result register(AdminLogin adminLogin) {
        AdminLogin login = adminMapper.register(adminLogin);
        if (login != null) {
            if (login.getUsername() != null && login.getPassword() != null) {
                return Result.error("400", "该用户已经被注册");
            }
        }
        int count = adminMapper.insertAdmin(adminLogin);
        if (count == 0) {
            return Result.error("400", "注册失败");
        }

        return Result.success("注册成功");
    }
}
